<html><head>
<title>chat</title>
<script src="../../../closure/closure/goog/base.js"></script>
<script src="deps.js"></script>
<script>
  goog.require('ptucker.Chat');
  goog.require('goog.dom');
  goog.require('goog.net.XhrIo');
  goog.require('goog.testing.MockControl');
  goog.require('goog.testing.asserts');
  goog.require('goog.testing.jsunit');
</script>
</head><body>
<script>
  var HOMER = {
    userId: 'h',
    email: 'homer@s.com',
    nickName: 'homer'
  };
  var MARGE = {
    userId: 'm',
    email: 'marge@s.com',
    nickName: 'marge'
  };
  var BART = {
    userId: 'b',
    email: 'bart@s.com',
    nickName: 'bart'
  };
  var LISA = {
    userId: 'l',
    email: 'lisa@s.com',
    nickName: 'lisa'
  };
  var MAGGIE = {
    userId: 'mg',
    email: 'maggie@s.com',
    nickName: 'maggie'
  };
  var EMPTY_ROOM = {
    id: 'emptyRoomId',
    name: 'emptyRoomName',
    presence: {
      'h': HOMER,
    }
  };
  var ROOM = {
    id: 'roomId',
    name: 'roomName',
    presence: [ MARGE, HOMER ]
  };
  var FULL_ROOM = {
    id: 'roomId',
    name: 'roomName',
    presence: [ MAGGIE, BART, LISA, MARGE, HOMER ]
  };
  var MSGS = [
    { seq: 5,
      timeMillis: 5,
      author: LISA,
      content: 'Bart!' },
    { seq: 4,
      timeMillis: 4,
      author: BART,
      content: 'eat my shorts' },
    { seq: 3,
      timeMillis: 3,
      author: MAGGIE,
      content: '...' },
    { seq: 2,
      timeMillis: 2,
      author: MARGE,
      content: 'hello, homer' },
    { seq: 1,
      timeMillis: 1,
      author: HOMER,
      content: 'hello, marge' }
  ];
  var mockControl;

  function setUp() {
    mockControl = new goog.testing.MockControl();
  }

  function tearDown() {
    mockControl.$tearDown();
    goog.dom.removeChildren(goog.dom.$('title'));
    goog.dom.removeChildren(goog.dom.$('msgs'));
  }

  function testCtorNoMsgs() {
    var chat = new ptucker.Chat(HOMER, EMPTY_ROOM);

    var title = goog.dom.$('title');
    assertEquals('', goog.dom.getTextContent(title));

    var msgs = goog.dom.$('msgs');
    assertEquals('', goog.dom.getTextContent(msgs));
  }

  function testCtorWithMsgs() {
    var chat = new ptucker.Chat(HOMER, ROOM, MSGS.slice(3, 5));

    var title = goog.dom.$('title');
    assertEquals('marge', goog.dom.getTextContent(title));

    var msgs = goog.dom.$('msgs');
    assertEquals(
        'me - hello, marge' +
        'marge - hello, homer',
        goog.dom.getTextContent(msgs));
  }

  function testCtorFullRoom() {
    var chat = new ptucker.Chat(HOMER, FULL_ROOM, MSGS);

    var title = goog.dom.$('title');
    assertEquals('maggie, bart, lisa and 1 more',
        goog.dom.getTextContent(title));

    var msgs = goog.dom.$('msgs');
    assertEquals(
        'me - hello, marge' +
        'marge - hello, homer' +
        'maggie - ...' +
        'bart - eat my shorts' +
        'lisa - Bart!',
        goog.dom.getTextContent(msgs));
  }

  // TODO(ptucker)
  // function testSend() {
  // }
</script>
TITLE:<div id=title></div>
MSGS:<div id=msgs></div>
<div id=pending style="display:none">
  <span id=pending-content></span>
  <img src="img/spinner.gif">
</div>
<div id=compose-container><textarea id=compose></textarea></div>
</body></html>
